<?php
namespace Home\Controller;
use Common\Controller\HomebaseController;
class IndexController extends  HomebaseController {
    public function index(){
        $articleModel = new \Common\Model\ArticleModel();
        $where = array('is_recycle'=>0,'status'=>1);
        $order = " is_top DESC,add_time DESC , aid DESC";
        $setConfig = array(
            'next' => 'Next →',
            'prev' => '← Previous',
        );
        $data = $articleModel->getListData(4,$where,$order,$setConfig);		
        $this->assign('data',$data);
        $this->assign('cocolait','');
        $this->display();
    }

	 public function ajaxGetMore(){
		 if(IS_AJAX){
			 $page = $_GET['p'];
			$articleModel = new \Common\Model\ArticleModel();
			$where = array('is_recycle'=>0,'status'=>1);
			$order = " is_top DESC,add_time DESC , aid DESC";
			//$Page = new \Think\Page(,4$page);

			$shu = 4*($page-1);
			$datas = $articleModel->query("select * from cp_article");
			$total = count($datas);
			$data = $articleModel->query("select * from cp_article order by add_time desc limit $shu, 4" );
			// if(count($data))
			// {
			// 	return  false;
			// }
			//var_dump($data);
			$this->assign('data',$data);
			$this->assign('cocolait','');
			$this->display();
	 }
    }
	//public function ajaxGetMore()
	//{
		//if(IS_AJAX)
		//{
			//$page = $_POST['p'];
			//$Data = M('article'); // 实例化Data数据对象  date 是你的表名
			////import('ORG.Util.Page');// 导入分页类
			//$map = array('is_recycle'=>0,'status'=>1);
    //$count = $Data->where($map)->count();// 查询满足要求的总记录数 $map表示查询条件
    //$Page = new \Think\Page($count,$page);// 实例化分页类 传入总记录数
    //$show = $Page->show();// 分页显示输出
    //// 进行分页数据查询
    //$list = $Data->where($map)->order('id')->limit($Page->firstRow.','.$Page->listRows)->select(); // $Page->firstRow 起始条数 $Page->listRows 获取多少条
    //$this->assign('list',$list);// 赋值数据集
    //$this->assign('page',$show);// 赋值分页输出
    //$this->display(); // 输出模板
		//}
	//}

	public function cheat_save(){
		$data = array();
		$data['title'] = trim(I('post.title',''));
		$data['url']   = trim(I('post.url',''));
		$data['create_at'] = date("Y-m-d H:i:s");
		$data['status']=1;
		
		if(M('cheat')->add($data)){
			die(json_encode(['code'=>'ok','msg'=>'添加成功']));
		}else{
			die(json_encode(['code'=>'error','msg'=>'添加失败！']));
		}
	}
}
